home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / ZSI / twisted / reverse.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  85 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from ZSI import _get_element_nsuri_name, SoapWriter, ParsedSoap
  5. from interfaces import HandlerChainInterface
  6. from zope.interface import classProvides, implements, Interface
  7.  
  8. class DataHandler:
  9.     classProvides(HandlerChainInterface)
  10.     readerClass = None
  11.     
  12.     def processRequest(cls, input, **kw):
  13.         return ParsedSoap(input, readerclass = cls.readerClass)
  14.  
  15.     processRequest = classmethod(processRequest)
  16.     
  17.     def processResponse(cls, sw, **kw):
  18.         return str(sw)
  19.  
  20.     processResponse = classmethod(processResponse)
  21.  
  22.  
  23. class CallbackHandler:
  24.     classProvides(HandlerChainInterface)
  25.     writerClass = None
  26.     
  27.     def processRequest(cls, ps, **kw):
  28.         resource = kw['resource']
  29.         request = kw['request']
  30.         method = getattr(resource, 'soap_%s' % _get_element_nsuri_name(ps.body_root)[-1])
  31.         
  32.         try:
  33.             (req, rsp) = method(ps, request = request)
  34.         except Exception:
  35.             ex = None
  36.             raise 
  37.  
  38.         return rsp
  39.  
  40.     processRequest = classmethod(processRequest)
  41.     
  42.     def processResponse(cls, output, **kw):
  43.         sw = SoapWriter(outputclass = cls.writerClass)
  44.         sw.serialize(output)
  45.         return sw
  46.  
  47.     processResponse = classmethod(processResponse)
  48.  
  49.  
  50. class ReverseHandlerChain:
  51.     
  52.     def __init__(self, *handlers):
  53.         self.in_handlers = handlers
  54.         handlers = list(handlers)
  55.         handlers.reverse()
  56.         self.out_handlers = tuple(handlers)
  57.  
  58.     
  59.     def processRequest(self, arg, **kw):
  60.         for h in self.in_handlers:
  61.             arg = h.processRequest(arg, **kw)
  62.         
  63.         return arg
  64.  
  65.     
  66.     def processResponse(self, arg, **kw):
  67.         if arg is None:
  68.             return None
  69.         
  70.         for h in self.out_handlers:
  71.             arg = h.processResponse(arg, **kw)
  72.         
  73.         return arg
  74.  
  75.  
  76.  
  77. class ReverseHandlerChainFactory:
  78.     protocol = ReverseHandlerChain
  79.     
  80.     def newInstance(cls):
  81.         return cls.protocol(DataHandler, CallbackHandler)
  82.  
  83.     newInstance = classmethod(newInstance)
  84.  
  85.